********************************************************************************
********"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*****
********************************************************************************

********************************************************************************
********************************************************************************
**********************************2019******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**#Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans2019, case(lower)
run RO_creditregister tm(2019m2) tm(2020m2) 0
keep bankid borrowerid time disbur

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2019, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m8, keepus(exlnassets excashas)
keep if _merge==3
drop _merge

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2019, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2019m3)&time<=tm(2020m2)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_CGP322019, keepus(cgasover cgasoverU)
keep if _merge!=2
drop _merge
recode cgasover (.=0)
recode cgasoverU (.=0)

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_TP322019, keepus(tradingover)
keep if _merge!=2
drop _merge
recode tradingover (.=0)

run RO_tdummies 2019 1
run RO_tdintera 1 "exlnassets excashas cgasover cgasoverU tradingover "

**#Bookmark (output - columns 1 and 2)
est clear
cd $outputdirectory
reghdfe $y dT7cgasover dT7tradingover dT7exlnassets dT7excashas lncrefin $regcommands
est save TAB7_C1234
reghdfe $y dT7cgasoverU dT7tradingover dT7exlnassets dT7excashas lncrefin $regcommands
est save TAB7_C1234, append
cd ..


********************************************************************************
********************************************************************************
**********************************2015******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**#**#Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**#**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**#**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(exlnassets excashas)
keep if _merge==3
drop _merge

**#**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)
 
**#**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_CGP32015, keepus(cgasover cgasoverU)
keep if _merge!=2
drop _merge
recode cgasover (.=0)
recode cgasoverU (.=0)

**#**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_TP322015, keepus(tradingover)
keep if _merge!=2
drop _merge
recode tradingover (.=0)

run RO_tdummies 2015 1
run RO_tdintera 1 "exlnassets excashas cgasover cgasoverU tradingover "

**#Bookmark (output - columns 3 and 4)
est clear
cd $outputdirectory
reghdfe $y dT7cgasover dT7tradingover dT7exlnassets dT7excashas lncrefin $regcommands
est save TAB7_C1234, append
reghdfe $y dT7cgasoverU dT7tradingover dT7exlnassets dT7excashas lncrefin $regcommands
est save TAB7_C1234, append
cd ..


